﻿using System;
using TpBaseObjects.Properties;
using Microsoft.Office.Interop.Excel;
using TpExtensions;
using System.IO;
using System.Globalization;

namespace TpBaseObjects.Base {

    public class ProjectRow {

        #region Members

        private Range myRow;
        private int startRow = 0;

        #endregion

        #region Contructor

        public ProjectRow(Range row) {
            myRow = row;
        }

        #endregion

        #region Properties

        public int Auftragsnummer {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "AE"];
                if (r1.Value != null) {
                    int.TryParse(r1.Value.ToString(), out ret);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "AE"];
                r1.Value = value;
            }
        }

        public string AusgangsrechnungsNr {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "R"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "R"];
                r1.Value = value;
            }
        }

        public DateTime Bestelldatum {
            get {
                DateTime ret = new DateTime(1900, 1, 1);
                Range r1 = myRow.Cells[1, "I"];
                if (r1.Value != null) {
                    if (DateTime.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "I"];
                r1.Value = value;
            }
        }

        public string BestellNr {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "J"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "J"];
                r1.Value = value;
            }
        }

        public bool BildeSumme {
            get {

                if (RowType == "S4") {
                    return true;
                }

                if (RowTerm == null | RowTerm == string.Empty) {
                    return false;
                }

                if (RowTerm.Contains("S")) {
                    return true;
                }

                Range r1 = myRow.Cells[1, 10]; //Wegen Kompbtibilität mit vorigen Versionen
                string s1 = Convert.ToString(r1.Value);
                if (Extensions.Nz(s1, "").Contains("S")) {
                    return true;
                }

                return false;
            }
        }

        public string Bereich {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "C"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                Range ba = myRow.Cells[1, "BA"];
                if (ba.Value != null) {
                    string v = Convert.ToString(ba.Value);
                    if (v.IsNumeric(NumberStyles.Any)) {
                        if (v.ToUpper().Contains("KUND")) {
                            ret = "Kund";
                        }
                        if (v.ToUpper().Contains("VERK")) {
                            ret = "Verk";
                        }
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "C"];
                r1.Value = value;
            }
        }

        public DateTime ChangeDate {
            get {
                Range r1 = myRow.Cells[1, "AZ"];
                DateTime ret = new DateTime(1900, 1, 1);
                if (r1.Value != null) {
                    if (DateTime.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public double ChangeBeginTime {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "BA"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public double ChangeEndTime {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "BB"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public double ChangeFlatTime {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "BD"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public double ChangeQuantity {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "BE"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public double ChangePerformance {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "BC"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public string ChangeType {
            get {
                Range r1 = myRow.Cells[1, "AY"];
                string t1 = Convert.ToString(r1.Value);
                if (t1 == null) {
                    return "";
                }
                return Extensions.Nz(t1.ToUpper(), "");
            }
            set {
                Range r1 = myRow.Cells[1, "AY"];
                r1.Value = value;
            }
        }

        public int CurrentRowNumber {
            get {
                int ret = myRow.Row;
                return ret;
            }
        }

        public string Datei {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "G"];
                if (r1.Value != null) {
                    string t1 = Convert.ToString(r1.Value);
                    ret = t1;
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "G"];
                r1.Value = value;
            }
        }

        public int DeleteRowNumber {
            get {
                return startRow;
            }
        }

        public string Durchführender1 {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, Settings.Default.SpalteDurchführender1];
                if (r1.Value != null) {
                    string t1 = Convert.ToString(r1.Value);
                    if (Extensions.TpUser.Contains(t1)) {
                        return t1;
                    }
                    ret = "Err";
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteDurchführender1];
                r1.Value = value;
            }
        }

        public string Durchführender2 {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, Settings.Default.SpalteDurchführender2];
                if (r1.Value != null) {
                    string t1 = Convert.ToString(r1.Value);
                    if (Extensions.TpUser.Contains(t1)) {
                        return t1;
                    }
                    ret = "Err";
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteDurchführender2];
                r1.Value = value;
            }
        }

        public string EingangsrechnungsNr {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "S"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "S"];
                r1.Value = value;
            }
        }

        public string Einheit {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteEinheit];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "");
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteEinheit];
                r1.Value = value;
            }
        }

        public double Einzelpreis {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "AQ"];
                if (r1.Value != null) {
                    double.TryParse(r1.Value.ToString(), out ret);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "AQ"];
                r1.Value = value;
            }
        }

        public double EkVorSk {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "BG"];
                if (r1.Value != null) {
                    double.TryParse(r1.Value.ToString(), out ret);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "BG"];
                r1.Value = value;
            }
        }

        public string Firma {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "B"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "B"];
                r1.Value = value;
            }
        }

        public string Fahrzeug {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, Settings.Default.SpalteFahrzeug];
                if (r1.Value != null) {
                    string t1 = Convert.ToString(r1.Value);
                    if (Extensions.TpFahrzeuge.Contains(t1)) {
                        return t1;
                    }
                    return "Err";
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteFahrzeug];
                r1.Value = value;
            }
        }

        public bool IsGesamtSummenZeile {
            get {
                Range r1 = myRow.Cells[1, 2];
                if (r1 != null) {
                    string t1 = Convert.ToString(r1.Value);
                    if (Extensions.Nz(t1, "").ToUpper().Contains("SUMME")) {
                        return true;
                    }
                }
                return false;
            }
        }

        public string Hyperlink {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "J"];
                string t1 = Convert.ToString(r1.Value);
                if (t1 != null) {
                    ret = t1;
                }
                return ret;
            }
            set {
                string address;
                Range r3 = myRow.Cells[1, "J"];
                if (value != null) {
                    address = value;
                    r3.Value = "";
                    if (!String.IsNullOrEmpty(address)) {
                        string display = new FileInfo(address).Name;
                        r3.Hyperlinks.Add(r3, Address: address, TextToDisplay: display);
                    }
                } else {
                    r3.Value = "";
                }

            }
        }

        public string HyperlinkPath {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "J"];
                if (r1.Hyperlinks.Count > 0) {
                    ret = r1.Hyperlinks[1].Address;
                }
                return ret;
            }
        }

        public bool IsEmpty {
            get {
                string t1 = "";
                Range r1 = myRow.Cells[1, 2];
                if (r1 != null) {
                    t1 = Convert.ToString(r1.Value);
                }
                if (Extensions.Nz(t1, "").ToUpper().Contains("SUMME")) {
                    return false;
                }
                if (this.JobOrt == "" && (this.RowText == " " || this.RowText == "")) {
                    return true;
                }
                return false;
            }
        }

        public bool IsEpRow {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteSummeEp];
                string t1 = Convert.ToString(r1.Value);
                double d1 = 0;
                if (t1.IsNumeric(System.Globalization.NumberStyles.Any)) {
                    d1 = Convert.ToDouble(r1.Value);
                }
                return Extensions.Nz(d1, 0) != 0;
            }
        }

        public bool IsLeOrLa {
            get {
                bool ret = false;
                Range r1 = myRow.Cells[1, Settings.Default.SpalteZeilenArt];
                if (r1.Value != null) {
                    string t1 = Convert.ToString(r1.Value);
                    return (t1.ToUpper() == "LE" | t1.ToUpper() == "LA" | t1.ToUpper() == "AU");
                }
                return ret;
            }
        }

        public bool IsProjectJob {
            get {
                bool isProJob;
                string cellValue = Extensions.Nz(Convert.ToString(Spalte("G")), "");
                string arValue = Extensions.Nz(Convert.ToString(Spalte("AR")), "");
                isProJob = (cellValue == "Kund" | cellValue == "Verk" | cellValue == "Verl");
                if (!isProJob) {
                    isProJob = arValue != "";
                }
                return isProJob;
            }
        }

        public bool IsRabattZeile {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteZeilenArt];
                string t1 = Convert.ToString(r1.Value);
                if (Extensions.Nz(t1, "").ToUpper() == "RA") {
                    return true;
                }
                return false;
            }
        }

        public bool IsReadyForExport {
            get {
                bool ret1 = (((JobDatum.Date <= DateTime.Today & !LeistungExported) & !JobExported));

                if (JobDatum.Date == new DateTime(1900, 1, 1).Date) {
                    ret1 = false;
                }

                if (!this.IsPauschalTime) {
                    if (this.JobTime == 0) {
                        return false;
                    }
                    if (this.JobEndTime < this.JobTime) {
                        return false;
                    }
                }
                return ret1;
            }
        }

        public bool IsReadyForExportExpense {
            get {
                bool ret = false;
                if (this.JobOrt.ToUpper() != "LF"
                    && this.Job.Contains("fahrt")
                    && (this.Durchführender1 != ""
                    || this.Durchführender2 != ""
                    )) {
                    ret = true;
                }
                return ret;
            }
        }

        public bool IsReadyForJobevidenz {
            get {
                bool r1 = JobDatum > DateTime.Today & !JobExported;
                return r1;
            }
        }

        public bool IsReadyForInternalJobevidenz {
            get {
                bool r1 = JobDatum > DateTime.Today.AddDays(-1);
                return r1;
            }
        }

        public bool IsReadyToStorno {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteExported];
                string t1 = Extensions.Nz(Convert.ToString(r1.Value), "");
                return t1.ToUpper() == "S";
            }
        }

        public bool IsPauschalTime {
            get {
                Range r1 = myRow.Cells[1, "AL"];
                string t1 = "";
                if (r1.Value != null) {
                    t1 = Extensions.Nz(Convert.ToString(r1.Value), "");
                }
                return t1.ToUpper() == "PA";
            }
        }

        public bool IsSummeGesamt {
            get {
                bool ret = false;
                Range r1 = myRow.Cells[1, "AF"];
                if (r1.Value != null) {
                    string t1 = r1.Value.ToString();
                    if (t1.ToUpper().Contains("GESAMT")) {
                        ret = true;
                    }
                }
                return ret;
            }
        }

        public bool IsSummeNetto {
            get {
                bool ret = false;
                Range r1 = myRow.Cells[1, "AF"];
                if (r1.Value != null) {
                    string t1 = r1.Value.ToString();
                    if (t1.ToUpper().Contains("SUMME NETTO")) {
                        ret = true;
                    }
                }
                return ret;
            }
        }

        public bool IsSummenZeile {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteSummeVp];
                string t1 = Convert.ToString(r1.FormulaR1C1);
                if (Extensions.Nz(t1, "").Contains("SUM")) {
                    return true;
                }
                r1 = myRow.Cells[1, 1];
                if (r1.Value != null) {
                    string sum = Convert.ToString(r1.Value);
                    if (sum.Contains("Su")) {
                        return true;
                    }
                }
                return false;
            }
        }

        public bool IsVpRow {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteSummeVp];
                string t1 = Convert.ToString(r1.Value);
                double d1 = 0;
                if (t1.IsNumeric(System.Globalization.NumberStyles.Any)) {
                    d1 = Convert.ToDouble(r1.Value);
                }
                return Extensions.Nz(d1, 0) != 0;
            }
        }

        public string Job {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "AF"];
                if (r1.Value != null) {
                    ret = r1.Value.ToString();
                }
                return ret;
            }
        }

        public string JobDetail {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "AG"];
                if (r1.Value != null) {
                    ret = r1.Value.ToString();
                }
                return ret;
            }
        }

        public DateTime JobDatum {
            get {
                DateTime ret = new DateTime(1900, 1, 1);
                Range r1 = myRow.Cells[1, "K"];
                if (r1.Value != null) {
                    if (DateTime.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "K"];
                if (value != new DateTime(1900, 1, 1)) {
                    r1.Value = value.ToString("yyyy/MM/dd");
                    r1 = myRow.Cells[1, "L"];
                    r1.Value = value.ToString("yyyy/MM/dd");
                } else {
                    r1.Value = "";
                }
            }
        }

        public string JobCharacter {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "U"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "U"];
                r1.Value = value;
            }
        }

        public bool JobEvidenz {
            get {
                string t1 = "";
                bool ret = false;
                Range r1 = myRow.Cells[1, "AE"];
                if (r1.Value != null) {
                    t1 = Convert.ToString(r1.Value);
                    ret = (t1.ToUpper() == "JE");
                }
                return ret;
            }
        }

        public bool JobExported {
            get {
                string t1 = "";
                bool ret = false;
                Range r1 = myRow.Cells[1, "AE"];
                if (r1.Value != null) {
                    t1 = Convert.ToString(r1.Value);
                    ret = (t1.ToUpper() == "LE" || t1.ToUpper() == "JE");
                }
                return ret;
            }
        }

        public double JobTime {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "P"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                double s1 = value;
                Range r1 = myRow.Cells[1, "P"];
                r1.Value = s1;
            }
        }

        public int JobType {
            get {
                int s1 = 0;
                Range r1 = myRow.Cells[1, "I"];
                if (r1.Value != null) {
                    Int32.TryParse(Convert.ToString(r1.Value), out s1);
                }
                return s1;
            }
            set {
                int s1 = value;
                Range r1 = myRow.Cells[1, "I"];
                r1.Value = s1;
            }
        }

        public double JobEndTime {
            get {
                double s1 = 0;
                Range r1 = myRow.Cells[1, "Q"];
                if (r1.Value != null) {
                    if (double.TryParse(r1.Value.ToString(), out s1)) {
                        return s1;
                    }
                }
                return s1;
            }
            set {
                double s1 = value;
                Range r1 = myRow.Cells[1, "Q"];
                r1.Value = s1;
            }
        }

        public int JobWeek {
            get {
                DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
                Calendar cal = dfi.Calendar;
                return cal.GetWeekOfYear(this.JobDatum, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
            }
        }

        public DateTime JobWeekFirstDay {
            get {
                DateTime d1 = this.JobDatum;
                while (d1.DayOfWeek != DayOfWeek.Monday) {
                    d1 = d1.AddDays(-1);
                }
                return d1;
            }
        }

        public DateTime JobWeekLastDay {
            get {
                DateTime d1 = this.JobDatum;
                while (d1.DayOfWeek != DayOfWeek.Sunday) {
                    d1 = d1.AddDays(1);
                }
                return d1;
            }
        }

        public string KundenName {
            get {
                Range r1 = myRow.Cells[1, "C"];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "");
            }
            set {
                Range r1 = myRow.Cells[1, "C"];
                r1.Value = value;
            }
        }

        public string Leistung {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteText];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "");
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteText];
                r1.Value = value;
            }
        }

        public string Lieferant {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "AD"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "AD"];
                r1.Value = value;
            }
        }

        public string JobOrt {
            get {
                Range r1 = myRow.Cells[1, "M"];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "");
            }
            set {
                Range r1 = myRow.Cells[1, "M"];
                r1.Value = value;
            }
        }

        public bool LeistungExported {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteExported];
                string t1 = Extensions.Nz(Convert.ToString(r1.Value), "");
                return t1.ToUpper() == "LE";
            }
        }

        public double LeistungProzent {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, Settings.Default.SpalteLeistungProzent];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteLeistungProzent];
                r1.Value = value;
            }
        }

        public double LeistungZeit {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, Settings.Default.SpalteLeistungZeit];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteLeistungZeit];
                r1.Value = value;
            }
        }

        public double PauschalZeit {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "U"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "U"];
                r1.Value = value;
            }
        }

        public double LeistungZeitSumme {
            get {
                Range r1 = myRow.Cells[1, "AV"];
                double ret = 0.0;
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "AV"];
                r1.Value = value;
            }
        }

        public double Menge {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, Settings.Default.SpalteMenge];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteMenge];
                r1.Value = value;
            }
        }

        public Range MyRow {
            get { return myRow; }
        }

        public string Organisation {
            get {
                Range r1 = myRow.Cells[1, "W"];
                string ret = "";
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
        }

        public string OrganisationName {
            get {
                Range r1 = myRow.Cells[1, "C"];
                string ret = "";
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
        }

        public string ProjectName {
            get {
                Range r1 = myRow.Cells[1, "D"];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "");
            }
            set {
                Range r1 = myRow.Cells[1, "D"];
                r1.Value = value;
            }
        }

        public double RabattProzent {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "AM"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public bool RechnungExported {
            get {
                string t1 = "";
                Range r1 = myRow.Cells[1, "BB"];
                if (r1.Value != null) {
                    t1 = Convert.ToString(r1.Value);
                }
                return Extensions.Nz(t1, "").ToUpper() == "AR";
            }
        }

        public int RechnungsNummer {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "S"];
                if (r1.Value != null) {
                    if (int.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "S"];
                r1.Value = value;
            }
        }

        public string RowID {
            get {
                Range r1 = myRow.Cells[1, "BA"];
                string ret = "";
                if (r1.Value != null) {
                    string t1 = Convert.ToString(r1.Value);
                    return Extensions.Nz(t1, "");
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "BA"];
                r1.Value = value;
            }
        }

        public string RowInvoiceMarkup {
            get {
                string t1 = "";
                Range r1 = myRow.Cells[1, "BB"];
                if (r1.Value != null) {
                    t1 = Convert.ToString(r1.Value);
                }
                return t1;
            }
            set {
                Range r1 = myRow.Cells[1, "BB"];
                r1.Value = value;
            }
        }

        public string RowLeistung {
            get {
                string t1 = "";
                Range r1 = myRow.Cells[1, "M"];
                if (r1.Value != null) {
                    t1 = Convert.ToString(r1.Value);
                }
                return t1;
            }
            set {
                Range r1 = myRow.Cells[1, "M"];
                r1.Value = value;
            }
        }

        public int RowNumber {
            get;
            set;
        }

        public string RowTerm {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "M"];
                if (r1.Value != null) {
                    ret = r1.Value.ToString();
                }
                return ret;
            }
        }

        public string RowText {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteText];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "");
            }
        }

        public string RowType {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "A"];
                if (r1.Value != null) {
                    ret = r1.Value.ToString();
                }
                return ret;
            }
        }

        public string S4Type {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteSummenText];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "");
            }
        }

        public string Stellvertreter {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteStellvertreter];
                string s1 = Extensions.Nz(Convert.ToString(r1.Value), "");
                if (!Extensions.TpUser.Contains(s1)) {
                    s1 = "";
                }
                return s1;
            }
            set {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteStellvertreter];
                string t1 = Extensions.Nz(Convert.ToString(value), "");
                if (Extensions.TpUser.Contains(t1) | value == "") {
                    r1.Value = value;
                }
            }
        }

        public string Subbereich {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "E"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                if (this.Bereich.ToUpper() == "KUND" || this.Bereich.ToUpper() == "VERK") {
                    ret = "";
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "E"];
                r1.Value = value;
            }
        }

        public string SubSubBereich {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "F"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                if (this.Bereich.ToUpper() == "KUND" || this.Bereich.ToUpper() == "VERK") {
                    ret = "";
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "F"];
                r1.Value = value;
            }
        }

        public double SummeEp {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "AS"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "AS"];
                r1.Value = value;
            }
        }

        public int SummenHierachie {
            get {
                if (RowType == "S4") {
                    return 4;
                }
                Range r1 = myRow.Cells[1, Settings.Default.SpalteSummeVp];
                if (Extensions.Nz(r1.FormulaR1C1, "") != "") {
                    if (Extensions.Right(r1.FormulaR1C1, 1) == ")") {
                        return 1;
                    }
                    if (Extensions.Right(r1.FormulaR1C1, 2) == "/2") {
                        return 2;
                    }
                    if (Extensions.Right(r1.FormulaR1C1, 2) == "/3") {
                        return 3;
                    }
                    if (Extensions.Right(r1.FormulaR1C1, 2) == "/4") {
                        return 4;
                    }
                }
                return 0;
            }
        }

        public string SummenText {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteSummenText];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "");
            }
        }

        public double SummeVp {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, Settings.Default.SpalteSummeVp];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public string Teilbereich {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "D"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                if (ret.ToUpper() == "KUND" || ret.ToUpper() == "VERK") {
                    ret = "";
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "D"];
                r1.Value = value;
            }
        }

        public bool Ust {
            get {
                Range r1 = myRow.Cells[1, Settings.Default.SpalteSummenText];
                string t1 = Convert.ToString(r1.Value);
                return Extensions.Nz(t1, "").ToUpper() == "UMSATZSTEUER";
            }
        }

        public string Veranlasser {
            get {
                Range r1 = myRow.Cells[1, "AY"];
                string ret = "";
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "AZ"];
                r1.Value = value;
            }

        }

        public DateTime VeranlasserDatum {
            get {
                DateTime ret = new DateTime(1900, 1, 1);
                Range r1 = myRow.Cells[1, "AX"];
                if (r1.Value != null) {
                    if (DateTime.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "AX"];
                if (value != new DateTime(1900, 1, 1)) {
                    r1.Value = value.ToString("yyyy/MM/dd");
                } else {
                    r1.Value = "";
                }
            }
        }

        public string Vr {
            get {
                Range r1 = myRow.Cells[1, "H"];
                string ret = "";
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "H"];
                r1.Value = value;
            }
        }

        #endregion

        #region Methods

        public void ClearContent() {
            MyRow.ClearContents();
            MyRow.ClearComments();
            //MyRow.Font.Name = Extensions.tpFontNormal;
            Extensions.SetFontBoldOrNormal(MyRow, Extensions.tpFont.Regular);
        }

        public void MarkAsFailed() {
            myRow.Interior.Color = Global.RGB(0, 255, 255);
        }

        public void MarkDurchFuehrender1AsFaild() {
            Range r1 = myRow.Cells[1, "N"];
            r1.Interior.Color = Global.RGB(0, 255, 255);
        }

        public void ResetJobDatum() {
            Range r1 = myRow.Cells[1, Settings.Default.SpalteJobDatum];
            r1.Value = "";
        }

        public void SetExported(string export) {
            Range r1 = myRow.Cells[1, Settings.Default.SpalteExported];
            r1.Value = export;
        }

        public void SetFontBold(bool bold) {
            Range r1 = myRow.Rows[1];
            //r1.Select();
            //r1.Font.Name = Extensions.tpFontBold;
            if (bold) {
                Extensions.SetFontBoldOrNormal(r1, Extensions.tpFont.Bold);
            } else {
                Extensions.SetFontBoldOrNormal(r1, Extensions.tpFont.Regular);
            }
        }

        public void ClearTpCells(out string errMsg) {
            errMsg = "";
            try {
                if (ProjectName.Length > 0) {
                    if (ProjectName.Left(1).IsNumeric(System.Globalization.NumberStyles.Any)) {
                        Range r1 = myRow.Cells[1, "E"];
                        r1.ClearContents();
                        r1 = myRow.Cells[1, "F"];
                        r1.ClearContents();
                        r1 = myRow.Cells[1, "G"];
                        r1.ClearContents();
                        r1 = myRow.Cells[1, "H"];
                        r1.ClearContents();
                        r1 = myRow.Cells[1, "AW"];
                        r1.ClearContents();
                        r1 = myRow.Cells[1, "AX"];
                        r1.ClearContents();
                        r1 = myRow.Cells[1, "AY"];
                        r1.ClearContents();
                        r1 = myRow.Cells[1, "AZ"];
                        r1.ClearContents();
                    }
                }
            } catch (Exception ex) {
                errMsg = ex.Message;
            }
        }

        #endregion

        #region Functions

        public object Spalte(string spaltenName) {
            Range r1 = myRow.Cells[1, spaltenName];
            object retObj = "";
            object rowObj = r1.Value;
            if (r1.Value != null) {
                if (Extensions.isNumeric(rowObj.ToString(), System.Globalization.NumberStyles.Any)) {
                    retObj = r1.Value;
                    return retObj;
                } else {
                    return Extensions.Nz(r1.Value, "");
                }
            }
            return retObj;
        }

        #endregion

        #region Overrides

        public override bool Equals(object obj) {
            bool equals = false;
            ProjectRow objRow = obj as ProjectRow;
            if (objRow.Durchführender1 == this.Durchführender1 && objRow.Durchführender2 == this.Durchführender2
                && objRow.Einheit == this.Einheit && objRow.Fahrzeug == this.Fahrzeug
                && objRow.IsEpRow == this.IsEpRow && objRow.IsLeOrLa == this.IsLeOrLa
                && objRow.IsRabattZeile == this.IsRabattZeile && objRow.IsSummenZeile == this.IsSummenZeile
                && objRow.IsVpRow == this.IsVpRow && objRow.JobDatum == this.JobDatum
                && objRow.KundenName == this.KundenName && objRow.Leistung == this.Leistung
                && objRow.LeistungProzent == this.LeistungProzent && objRow.LeistungZeit == this.LeistungZeit
                && objRow.Menge == this.Menge && objRow.RabattProzent == this.RabattProzent
                && objRow.RowLeistung == this.RowLeistung && objRow.RowTerm == this.RowTerm
                && objRow.RowText == this.RowText && objRow.RowType == this.RowType
                && objRow.SummenText == this.SummenText) {
                equals = true;

            }
            return equals;
        }

        public override int GetHashCode() {
            return base.GetHashCode();
        }

        #endregion

    }
}
